<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			#box>div{
				width: 500px;
				height: 200px;
				background-color: aqua;
			}
		</style>
	</head>
	<body>
		<div id="box">box text
			<button>click</button>
			<em>em text</em>
		</div>
		
		<script>
			var btn = document.querySelector('button');
			btn.addEventListener('click',function(){
				const newDiv = document.createElement('div');
				const divTxt = document.createTextNode("this is a newDiv");
				newDiv.appendChild(divTxt);
				box.appendChild(newDiv);
				const newSpan = document.createElement("span");
				newSpan.innerHTML = "this is a newSpan";
				box.insertBefore(newSpan,btn);
				const emElem = document.querySelector('em');
				box.removeChild(emElem);
			})
		</script>
	</body>
</html>